package com.k7.mobile.platform.bo.impl;

import java.util.List;

import com.k7.mobile.platform.bo.ILogBO;
import com.k7.mobile.platform.dao.ILogDAO;
import com.k7.mobile.platform.dataobject.LogDO;
import com.k7.mobile.platform.exception.BOException;

public class LogBOImpl extends BaseBOImpl implements ILogBO {

	private ILogDAO logDAO;
	
	@Override
	public void addLog(LogDO logDO) throws BOException {
		if(logDO == null)
			throw new BOException("创建日志失败，日志对象为空.");
		
		try{
			logDAO.addLog(logDO);
		}catch(Exception e){
			log.error("LogBOImpl:addLog 创建日志失败.", e);
			throw new BOException("创建日志失败.", e);
		}
	}

	@Override
	public void addLog(List<LogDO> logDOList) throws BOException {
		if(logDOList == null)
			throw new BOException("创建日志失败，日志对象为空.");
		
		try{
			logDAO.addLog(logDOList);
		}catch(Exception e){
			log.error("LogBOImpl:addLog 创建日志失败.", e);
			throw new BOException("创建日志失败.", e);
		}
	}

	@Override
	public LogDO getLogById(Long logId)
			throws BOException {
		if(logId == null)
			return null;
		
		try{
			return logDAO.getLogById(logId);
		}catch(Exception e){
			log.error("LogBOImpl:getLogById 根据ID获取日志详情失败.", e);
			throw new BOException("根据ID获取日志详情失败.", e);
		}
	}

	@Override
	public List<LogDO> getLogList(LogDO queryDO)
			throws BOException {
		if(queryDO == null)
			throw new BOException("查询日志列表失败.查询条件对象为空.");
		
		try{
			return logDAO.getLogList(queryDO);
		}catch(Exception e){
			log.error("LogBOImpl:getLogList 获取日志列表失败.", e);
			throw new BOException("获取日志列表失败.", e);
		}
	}
	
	@Override
	public void saveLog(Long userId, Long targetId, String targetName, Integer logType, Integer optType, String opComment){
		LogDO log = new LogDO();
		log.setLogType(logType);
		log.setOptType(optType);
		log.setOpComment(opComment);
		log.setTargetId(targetId);
		log.setTargetName(targetName);
		log.setUserId(userId);
		
		addLog(log);
	}

	public void setLogDAO(ILogDAO logDAO) {
		this.logDAO = logDAO;
	}
	
}
